<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>采购入库统计分析</title>
    <script type="text/javascript">
      Ext.onReady(function(){

        var vendor =  Ext.create('Ext.form.ComboBox', {
          fieldLabel: '供应商',
          store: vendorStore,
          valueField: 'id',
          displayField: 'name',
          name: 'vendor_id',          
          loadingText: '搜索中...',
          anchor: '95%',          
          minChars: 0,
          editable:false          
        });

        //产品
        var productCBB = Ext.create('Ext.form.ComboBox', {
          store: productStore,
          fieldLabel: '产品',
          emptyText: '请选择...',
          valueField: 'id',
          displayField: 'name',
          name: 'product_id',
          loadingText: '搜索中...',
          anchor: '100%',
          pageSize: 10,
          minChars: 0,
          listConfig: {
            loadingText: 'Searching...',
            getInnerTpl: function() {
              return '<div style="float:left; width:200px" data-qtip="{name}">{name:ellipsis(18)}</div><div style="float:left; width:110px">{number}</div>{is_suit}';
            }
          }
        });
        
        var purchaseOrderNumber = Ext.create('Ext.form.field.Text', {
          fieldLabel: '采购单号',
          name: 'purchase_order_number',
          anchor: '95%'
        });

        var auditingStatus = Ext.create('Ext.form.ComboBox', {
          fieldLabel: '审批状态',
          store: auditStatusStore,
          displayField:'text',
          typeAhead: true,
          anchor: '95%',
          mode: 'local',
          name: 'auditing_status',
          forceSelection: true,          
          editable:false,
          valueField: 'value',
          emptyText:''          
        })

        var beginDate = Ext.create('Ext.form.field.Date', {
          fieldLabel: '入库日期从',
          name: 'begin_date',
          id: 'e_begin_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          allowBlank: false,
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",          
          anchor: '95%',
          vtype: 'daterange',
          endDateField: 'e_end_date'
        });

        var endDate = Ext.create('Ext.form.field.Date', {
          fieldLabel: '至    ',labelWidth:30,
          name: 'end_date',
          id: 'e_end_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          allowBlank: false,
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",
          labelWidth:30,
          anchor: '95%',
          vtype: 'daterange',
          startDateField: 'e_begin_date'
        });

        var showEntryInfo = Ext.create('Ext.form.field.Checkbox', {
          name: 'entry_info',
          clearCls: 'allow-float',
          itemCls: 'float-left',
          fieldLabel: '显示入库明细'
        })

        var submitButton = Ext.create('Ext.Button', {
          text: '搜索',
          iconCls: 'finding',
          handler: function(){
            if (queryFormPanel.form.isValid()) {
              purchaseEntryDS.removeAll();
              purchaseEntryDS.getProxy().extraParams.purchase_order_number = purchaseOrderNumber.getValue();
              purchaseEntryDS.getProxy().extraParams.auditing_status = auditingStatus.getValue();

              purchaseEntryDS.getProxy().extraParams.begin_date = beginDate.getRawValue();
              purchaseEntryDS.getProxy().extraParams.end_date = endDate.getRawValue();
              purchaseEntryDS.getProxy().extraParams.vendor_id = vendor.getValue();
              purchaseEntryDS.getProxy().extraParams.entry_info = showEntryInfo.getValue();
              purchaseEntryDS.getProxy().extraParams.product_id = productCBB.getValue();
              purchaseEntryDS.getProxy().extraParams.start = 0;
              purchaseEntryDS.load({callback: function(record, options, success){
                  if (financialManagement === '是'){
                    costPriceLabel.setText("成本总值:"+Ext.util.Format.number(Ext.JSON.decode(options.response.responseText).sum_cost_price_amount,'0,000.00'));
                    taxPriceLabel.setText("成本总值(含税):"+Ext.util.Format.number(Ext.JSON.decode(options.response.responseText).sum_tax_price_amount,'0,000.00'));
                  }
                }
              });
            }
          }
        });

        var clearButton = Ext.create('Ext.Button', {
          text: '清空',
          width:50,
          handler: function(){
            queryFormPanel.form.reset();
          }
        });

        var queryFormPanel = Ext.create('Ext.form.Panel', {
          fieldDefaults: {
            labelWidth: 65,
            labelAlign: 'right'
          },
          width: screenWidth-165,
          frame : true,
          border:false,
          items: [{
              xtype: 'fieldset',
              defaults: {width: 1100},
              title: '查询条件',
              border: true,
              items: [{
                  layout: 'column',
                  xtype: 'container',
                  items: [{
                      columnWidth: .16,
                      layout: 'anchor',
                      xtype: 'container',
                      labelWidth: 65,
                      items: [beginDate]
                    }, {
                      columnWidth: .13,
                      layout: 'anchor',
                      labelWidth: 35,
                      xtype: 'container',
                      items: [endDate]
                    }]
                },{
                  layout: 'column',
                  xtype: 'container',
                  items: [{
                      columnWidth: .25,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [vendor]
                    },{
                      columnWidth: .4,
                      layout: 'anchor',
                      xtype: 'container',
                      labelWidth: 65,
                      items: [productCBB]
                    }, {
                      columnWidth: .11,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [submitButton]
                    }, {
                      columnWidth: .11,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [clearButton]
                    }]
                }]
            }]
        });

        //成本总值
        var costPriceLabel = Ext.create('Ext.form.Label', {
          width:190,
          name: 'cost_price_label'
        })
        costPriceLabel.setText("成本总值:0");
        
        //成本总值(含税)
        var taxPriceLabel = Ext.create('Ext.form.Label', {
          width:190,
          name: 'tax_price_label'
        })
        taxPriceLabel.setText("成本总值(含税):0");
        
        //显示采购订单操作时的窗口介面。
        //----------------------------------采购订单Grid-------------------------
        //采购订单Grid Store
        Ext.define('PurchaseEntryModel', {
          extend : 'Ext.data.Model',
          fields : [{name: 'id'},
            {
              name: 'auditing_status'
            },{
              name: 'order_number'
            },{
              name: 'purchase_order_number'
            },{
              name: 'product_name'
            },{
              name: 'product_number'
            },{
              name: 'purchase_quantity'
            }, {
              name: 'purchase_auditing_status'
            }, {
              name: 'vendor_name'
            },{
              name: 'quantity',
              type: 'int'
            },{
              name: 'cost_price_amount',
              type: 'float'
            }, {
              name: 'cost_price',
              type: 'float'
            }, {
              name: 'tax_price',
              type: 'float'
            }, {
              name: 'store_status'
            },
            {name: 'created_at'},
            {name: 'updated_at'}
          ]
        });

        var purchaseEntryDS =  Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'PurchaseEntryModel',
          proxy : {
            type : 'ajax',
            url : '/stock/statisticsPurchaseEntry',
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          }
        });

        //生成要订单的产品的Grid
        var purchaseEntryGrid = Ext.create('Ext.grid.Panel', {
          title:'采购订单与入库单对比列表',
          store: purchaseEntryDS,
          columns : [Ext.create('Ext.grid.RowNumberer'),{
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '入库单单号',
              dataIndex: 'order_number',
              width: 120
            },{
              header: '入库单状态',
              dataIndex: 'auditing_status',
              renderer: auditingStatusRender,
              width: 80
            },{
              header: '采购订单单号',
              dataIndex: 'purchase_order_number',
              width: 120
            },{
              header: '采购订单状态',
              dataIndex: 'purchase_auditing_status',
              renderer: auditingStatusRender,
              width: 90
            },{
              header: '供应商',
              dataIndex: 'vendor_name',
              width: 90
            },{
              header: '产品名称',
              dataIndex: 'product_name',
              width: 230
            },{
              header: '产品编号',
              dataIndex: 'product_number',
              width: 80
            },{
              header: '入库数量',
              dataIndex: 'quantity',
              align:'right',
              width: 75
            },{
              header: '成本单价',
              dataIndex: 'cost_price',
              renderer: Ext.util.Format.numberRenderer('0,000.0000000000'),
              align:'right',
              width: 120
            },{
              header: '成本总额',
              dataIndex: 'cost_price_amount',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              align:'right',
              width: 75
            },{
              header: '成本单价(含税)',
              dataIndex: 'tax_price',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              align:'right',
              width: 110
            },{
              header: '发货日期',
              dataIndex: 'updated_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),width: 115
            }],
          loadMask: true,
          width: screenWidth-165,
          height: screenHeight-345,
          frame: true,
          //title: '进货品种列表',
          //plain:true,
          //plugins: checkColumn,
          bbar: [costPriceLabel,'-',taxPriceLabel]
        });

        //总的panel
        var workbenchPanel = Ext.create('Ext.form.Panel', {
          width: screenWidth-165,
          height: screenHeight-235,
          frame:false,          
          layout: {type: 'table',columns:1},          
          items:[queryFormPanel,purchaseEntryGrid]
        });
        workbenchPanel.render("statistics_purchase_entry");
      })
    </script>
  </head>
  <body>
    <div id="statistics_purchase_entry"></div>
  </body>
</html>